package org.example.myleet.rosalind.sexl;

import java.math.BigDecimal;
import java.math.RoundingMode;

/**
 * https://rosalind.info/problems/sexl/
 */
public class Solution {
    private static final BigDecimal TWO = BigDecimal.valueOf(2);
    public static void main(String[] args) {
        String input = "0.1 0.5 0.8";
//        String input = "0.0711694773268 0.077945054993 0.0785735117687 0.0786176365796 0.112985067234 0.232210147333 0.254724714573 0.29285675934 0.322576889757 0.534632718756 0.591044785517 0.716353776429 0.757612411231 0.826670647649 0.829090794066 0.837145868049 0.884834392332 0.944842210726 0.987598250839";
        String[] A = input.split(" ");
        int n = A.length;
        BigDecimal[] answer = new BigDecimal[n];
        //每个隐性基因的答案通过数学方式直接求出
        for (int k = 0; k < n; ++k) {
            //隐性基因的频率
            String pr = A[k];
            BigDecimal recessivePr = new BigDecimal(pr);
            //显性基因的频率 1 - Pr(recessive)
            BigDecimal dominantPr = BigDecimal.ONE.subtract(recessivePr);
            //Aa和aA的基因型频率是相同的，因此recessivePr.multiply(dominantPr)之后直接乘以2就可以得到第k个问的答案
            answer[k] = recessivePr.multiply(dominantPr).multiply(TWO);
        }
        for (BigDecimal a : answer) {
            System.out.printf("%s ", a.setScale(24, RoundingMode.HALF_UP).toPlainString());
        }
    }
}
